<!DOCTYPE html>
<html>
<head>
	<title>芭蕉花管理平台-修改密码</title>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
	<link rel="SHORTCUT ICON" href="/img/favicon.ico">
	<script type="text/javascript">
		var pathname = window.location.pathname;
		if (pathname != "/mobile/home.html") {
			location.href = '/';
		}
	</script>
	<style type="text/css">
		:root {
			--input-padding-x: .75rem;
			--input-padding-y: .75rem;
		}
		
		body {
			display: -ms-flexbox;
			display: -webkit-box;
			display: flex;
			-ms-flex-align: center;
			-ms-flex-pack: center;
			-webkit-box-align: center;
			align-items: center;
			-webkit-box-pack: center;
			justify-content: center;
			padding-top: 40px;
			padding-bottom: 40px;
		}
		
		.form-change {
			width: 100%;
			max-width: 420px;
			padding: 15px;
			margin: 0 auto;
		}
		
		.form-title {
			text-align: center;
			margin-bottom: 1rem;
			font-size: 30px;
			color: #666;
		}
		
		.form-label-group {
			position: relative;
			margin-bottom: 1rem;
		}
		
		.form-label-group>input, .form-label-group>label {
			height: auto;
			padding: var(--input-padding-y) var(--input-padding-x);
		}
		
		.form-label-group>label {
			position: absolute;
			top: 0;
			left: 0;
			display: block;
			width: 100%;
			margin-bottom: 0; /* Override default `<label>` margin */
			line-height: 1.5;
			color: #495057;
			border: 1px solid transparent;
			border-radius: .25rem;
			transition: all .1s ease-in-out;
		}
		
		.form-label-group input::-webkit-input-placeholder {
			color: transparent;
		}
		
		.form-label-group input:-ms-input-placeholder {
			color: transparent;
		}
		
		.form-label-group input::-ms-input-placeholder {
			color: transparent;
		}
		
		.form-label-group input::-moz-placeholder {
			color: transparent;
		}
		
		.form-label-group input::placeholder {
			color: transparent;
		}
		
		.form-label-group input:not(:placeholder-shown) {
			padding-top: calc(var(--input-padding-y) + var(--input-padding-y) * (2 / 3));
			padding-bottom: calc(var(--input-padding-y) / 3);
		}
		
		.form-label-group input:not(:placeholder-shown) ~ label {
			padding-top: calc(var(--input-padding-y) / 3);
			padding-bottom: calc(var(--input-padding-y) / 3);
			font-size: 12px;
			color: #777;
		}
	</style>
</head>
<body>
	<form class="form-change">
		<div class="form-title">修改密码</div>
		
		<input type="hidden" id="userId" name="userId">
		
		<div class="form-label-group">
			<input id="userName" name="userName" type="text" class="form-control" placeholder="用户名" autocomplete="off" maxlength="20" value="" readonly="readonly">
			<label for="userName">用户名</label>
		</div>
		
		<div class="form-label-group">
			<input id="oldPassword" name="oldPassword" type="password" class="form-control" placeholder="旧密码" autocomplete="off" maxlength="20" value="">
			<label for="oldPassword">旧密码</label>
		</div>
		
		<div class="form-label-group">
			<input id="newPassword" name="newPassword" type="password" class="form-control" placeholder="新密码" autocomplete="off" maxlength="20" value="">
			<label for="newPassword">新密码</label>
		</div>
		
		<div class="form-label-group">
			<input id="confirmNewPassword" name="confirmNewPassword" type="password" class="form-control" placeholder="确认新密码" autocomplete="off" maxlength="20" value="">
			<label for="confirmNewPassword">确认新密码</label>
		</div>
		
		<button id="doSave" type="button" class="btn btn-lg btn-primary btn-block btn-login">保&nbsp;&nbsp;存</button>
	</form>
</body>
<script type="text/javascript">
	// 初始化
	$(function () {
		$('#doSave').click(function() {
			var oldPassword = $("#oldPassword").val();
			var newPassword = $("#newPassword").val();
			var confirmNewPassword = $("#confirmNewPassword").val();
			if (oldPassword == "" || oldPassword == null) {
				showErrorMessageTip("请输入旧密码", "oldPassword");
				return;
			}
			if (newPassword == "" || newPassword == null) {
				showErrorMessageTip("请输入新密码", "newPassword");
				return;
			}
			if (confirmNewPassword == "" || confirmNewPassword == null) {
				showErrorMessageTip("请输入确认新密码", "confirmNewPassword");
				return;
			}
			if (newPassword != confirmNewPassword) {
				showErrorMessageTip("两次密码输入不一致", "newPassword");
				return;
			}
			var userId = $("#userId").val();
			var url_changePassword = "/sysadmin/updatePwd";
			var params_changePassword = {
				"id" : userId,
				"oldPassword" : oldPassword,
				"newPassword" : newPassword
			};
			getMapData(url_changePassword, params_changePassword, function(data, result) {
				if (result == "success") {
					getHtml('/mobile/menu.html');
				}
			}, true);
		});

		$(window).keydown(function(event) {
			if (event.which == 13) {
				$('#doSave').click();
			}
		});
		
		initSysInfo();
	});

	//初始化账号信息
	function initSysInfo() {
		var url_getLoginInfo = "/sys/getLoginInfo";
		var params_getLoginInfo = {};
		getMapData(url_getLoginInfo, params_getLoginInfo, function(data, result) {
			if (result == "success") {
				var userInfo = data.userInfo;
				$("#userId").val(userInfo.id);
				$("#userName").val(userInfo.account);
			}
		});
	}
</script>
</html>